package com.example.tys.baseapplication.util;

/**
 * Singleton helper class for lazily initialization.
 * <p>
 * private static final Singleton<TestManager> testSingleton = new Singleton<TestManager>() {
 *
 * @param <T> expect to be a singleton object
 * @Override protected TestManager createdInstance() {
 * return new TestManager();
 * }
 * };
 * <p>
 * public static TestManager get() { return testSingleton.get(); }
 *
 * @param <T> expect to be a singleton object
 */
public abstract class Singleton<T> {
    private T mInstance;

    protected abstract T create();

    public final T get() {
        synchronized (this) {
            if (mInstance == null) {
                mInstance = create();
            }
            return mInstance;
        }
    }
}
